/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package MyWidget;

import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.InputStream;

import javax.imageio.ImageIO;

/**
 *
 * @author KF-NRS
 */
public class BgImage
{
    private String path="/ImageFolder/bubble.png";
    private BufferedImage image;

    public String getPath()
    {
        return path;
    }

    public void setPath(String path)
    {
        if(path!=null&&!path.trim().equals("")&&!this.path.equals(path))
        {
            this.path = path;
            initImage();
        }
    }

    public BufferedImage getImage()
    {
        if(image==null) initImage();
        return image;
    }

    private void initImage()
    {
        InputStream is=null;
        try
        {
            //fis=new FileInputStream(this.path);
        	is = this.getClass().getResourceAsStream(this.path);
            image = ImageIO.read(is);
        }
        catch(IOException ex)
        {
           ex.printStackTrace();
        }finally
        {
            if(is!=null)
            {
                try
                {
                	is.close();
                }
                catch(IOException ex)
                {
                    ex.printStackTrace();
                }
            }
        }
    }

    private static BgImage singleton = null;

    private BgImage()
    {
    }

    public static BgImage getInstance()
    {
        if(singleton==null)
        {
            synchronized(BgImage.class)
            {
                if(singleton==null)
                {
                    singleton = new BgImage();
                }
            }
        }
        return singleton;
    }
}